package com.base.system.managedBean;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.Validate;
import org.operamasks.faces.user.util.Browser;

import com.base.common.config.CommonKeyConst;
import com.base.common.config.RepositoryConst;
import com.base.commonKey.entity.CommonKeyType;
import com.base.system.managedBean.baseBean.BaseCommonKeyTypeBean;

@ManagedBean(name = "system_addCommonKeyTypeBean", scope = ManagedBeanScope.REQUEST)
public class AddCommonKeyTypeBean extends BaseCommonKeyTypeBean {

	@Action(id = "saveCommonKeyType")
	public void saveCommonKey() {
		com = new CommonKeyType();
		setProperty();
		dao.saveOrUpdate(com);
		String script = "closeCenterLayoutTab('" + CommonKeyConst.ADD_TAB
				+ "')";
		Browser.execClientScript("window.top", script);
	}

	@Validate(id = "typeCode", message = "输入了非英文字符")
	private boolean validateItemName(String typeCode) {
		Pattern p = Pattern.compile(RepositoryConst.REPOSITORY_REGULAR_ENGLISH);
		Matcher m = p.matcher(typeCode);
		return m.matches();
	}
}
